<?php

  require_once "JooS/Server/Stream/Abstract.php";

  final class JooS_Server_Stream_Resource extends JooS_Server_Stream_Abstract {
    const STREAM_PROTOCOL = "joos";

    public static function stream_register() {
      parent::_stream_register(self::STREAM_PROTOCOL, __CLASS__);
    }

    public function stream_get_content($path) {
      $url = parse_url($path);

      $hostName = $url["host"];
      $requestUri = isset($url["path"]) ? $url["path"] : "/";

      require_once "JooS/Server/Request/Custom.php";
      $request = new JooS_Server_Request_Custom($hostName, $requestUri);
      if (isset($url["query"]))
        $request->setQueryString($url["query"]);
      
      $response = JooS_Server::handle($request);

      return $response->getBody();
    }
  }

?>